<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>版本信息编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/web/res/css/xadmin.css">
    <script src="/web/res/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/web/res/js/xadmin.js"></script>
    <style>
        .zsIMG {
            width: 100px;
            height: 100px;
            cursor: pointer;
        }
    </style>
</head>

<body style="background-color: white;">
<div class="layui-fluid" id="orderEdit">
    <form class="layui-form layui-form-pane" id="formsubmit" style="width: 500px;margin:20px auto"
          action="/after/game/zpJiangpinAddSave">


        <div class="layui-form-item" id="wai_url">
            <label class="layui-form-label">奖品名</label>
            <div class="layui-input-block">
                <input type="text" name="jpname" id="jpname" autocomplete="off"
                       class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">奖品类型</label>
            <div class="layui-input-block">
                <select name="jiangpinType" lay-filter="jiangpinType">
                    <option value="1">钻石</option>
                    <option value="2">钻石</option>
                    <option value="3">礼物</option>
                    <option value="4">贵族</option>
                </select>

            </div>
        </div>


        <div class="layui-form-item" id="zuanshi" style="display: block">
            <label class="layui-form-label">钻石数量</label>
            <div class="layui-input-block">
                <input type="number" name="zuanshiNum" id="zuanshiNum" value="1" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" id="jinbi" style="display: none">
            <label class="layui-form-label">钻石数量</label>
            <div class="layui-input-block">
                <input type="number" min="1" value="1" name="jinbiNum" id="jinbiNum" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" id="liwu"  style="display: none">
            <label class="layui-form-label">礼物id</label>
            <div class="layui-input-block">
                <select name="liwuNum" id="liwuNum"  style="margin: 0;">
                    <option value="">请选择礼物</option>
                    <#list liwulist as ll>
                    <option value="${(ll.id?c)!''}">${(ll.giftname?html)!''}</option>
                    </#list>
                </select>
            </div>
        </div>

        <div class="layui-form-item" id="guizu"  style="display: none">
            <label class="layui-form-label">贵族id</label>
            <div class="layui-input-block">
                <select name="guizuNum" id="guizuNum"  style="margin: 0;">
                    <option value="">请选择礼物</option>
                    <#list guizulist as gl>
                    <option value="${(gl.id?c)!''}">${(gl.name?html)!''}</option>
                    </#list>
                </select>
            </div>
        </div>


        <div class="layui-form-item" pane>
            <label class="layui-form-label lable-text-center">是否有效</label>
            <div class="layui-input-block">
                <input type="checkbox" name="state" id="state" value="1" lay-skin="switch" lay-text="是|否" checked/>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-radius" lay-submit lay-filter="save">&emsp;保存&emsp;
                </button>
                <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" onclick="xadmin.close()">
                    &emsp;返回&emsp;
                </button>
            </div>
        </div>
        <input type="hidden" id="zpJiangliTypeValue" name="zpJiangliTypeValue" value="1">

    </form>
</div>
<script>
    layui.use('form', function () {
        let $ = layui.$;
        var form = layui.form;
        form.render();

        $.fn.extend({
            serializeObject: function () {
                var obj = {}; //声明一个对象
                $.each(this.serializeArray(), function (index, field) {
                    obj[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
                })
                return obj;
            }
        });






        form.on('select(jiangpinType)', function (data) {
            var message = parseInt($("select[name=jiangpinType").val());
            console.log(message)
            if (message === 1) {
                $("#zuanshi").css("display", "block");
                $("#jinbi").css("display", "none");
                $("#liwu").css("display", "none");
                $("#guizu").css("display", "none");
                $("#zpJiangliTypeValue").val(1);
            } else if (message === 2) {
                $("#zuanshi").css("display", "none");
                $("#jinbi").css("display", "block");
                $("#liwu").css("display", "none");
                $("#guizu").css("display", "none");
                $("#zpJiangliTypeValue").val(2);
            } else if (message === 3) {
                $("#zuanshi").css("display", "none");
                $("#jinbi").css("display", "none");
                $("#liwu").css("display", "block");
                $("#guizu").css("display", "none");
                $("#zpJiangliTypeValue").val(3);
            } else if (message === 4) {
                $("#zuanshi").css("display", "none");
                $("#jinbi").css("display", "none");
                $("#liwu").css("display", "none");
                $("#guizu").css("display", "block");
                $("#zpJiangliTypeValue").val(4);
            }
        });

        var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;

        form.on('submit(' + $("button[lay-submit]:eq(0)").attr("lay-filter") + ')', function (data) {
            var type = parseInt($("#zpJiangliTypeValue").val());
            if ($("#jiangpinName").val() == '') {
                layer.msg("奖品名不能为空", {icon: 2, time: 1000});
                return false;
            }
            if (type === 2) {
                if ($("#zuanshiNum").val() == '') {
                    layer.msg("钻石不能为空", {icon: 2, time: 1000});
                    return false;
                }

            }
            var values = "";
            if (type === 1) {
                values = $("#zuanshiNum").val();
            } else if (type === 2) {
                values = $("#jinbiNum").val();
            } else if (type === 3) {
                values = $("#liwuNum").val();
            } else if (type === 4) {
                values = $("#guizuNum").val();
            }
            var states = "";
            if ($("#state").prop("checked")) {
                states = 1
            } else {
                states = 2
            }

            layer.confirm('确认要保存吗？', function (index) {

                ajaxPost($, "/after/game/zpJiangpinAddSave", {
                    jiangpinName: $("#jpname").val(),
                    values: values,
                    type: type,
                    state: states
                },function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000});
                        setTimeout(function () {
                            parent.location.reload();
                        }, 1000);
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 2000});
                    }

                });

            });

        });

    })
    ;


</script>
</body>

</html>